<template>
    <div class="edit-page">
      <h2 class="page-title">编辑用户信息</h2>
      <el-form :model="user" label-width="120px" class="form-container">
        <el-form-item label="用户名">
          <el-input v-model="user.username" placeholder="请输入用户名" class="input-field" />
        </el-form-item>
        <el-form-item label="电子邮件">
          <el-input v-model="user.email" placeholder="请输入电子邮件" class="input-field" />
        </el-form-item>
        <el-form-item label="电话">
          <el-input v-model="user.phone" placeholder="请输入电话" class="input-field" />
        </el-form-item>
        <el-form-item label="地址">
          <el-input v-model="user.address" placeholder="请输入地址" class="input-field" />
        </el-form-item>
        <el-button type="primary" @click="saveChanges" class="save-btn">保存</el-button>
      </el-form>
    </div>
  </template>
  
  <script>
  import { ElForm, ElInput, ElButton } from 'element-plus';
  import { ref } from 'vue';
  import router from '../../router';
  import { getUserInfo, updateUserInfo} from '../../api/user';
  
  export default {
    components: {
      ElForm,
      ElInput,
      ElButton,
    },
    setup() {
      const user = ref({
        username: '',
        email: '',
        phone: '',
        address: '',
      });
  
      const saveChanges = () => {
        console.log('保存信息:', user.value);
        router.push('/userinfo');
      };
  
      return {
        user,
        saveChanges,
      };
    },methods: {



      async fetchActivities() {
        try {
          var userId = localStorage.getItem("userId");
          console.log(userId);
          const response = await getUserInfo(userId);
          this.user.username = response.data.data.username;
          this.user.email = response.data.data.email;
          this.user.phone = response.data.data.phone;
          this.user.address = response.data.data.address;
        } catch (error) {
          console.error('Error fetching activities:', error);
        }
      },
    }, mounted() {
      this.fetchActivities();
    }
  };
  </script>
  
  <style scoped>
  .edit-page {
    max-width: 650px;
    margin: 50px auto;
    padding: 40px;
    background-image: url('/src/assets/bianji.png'); 
    background-size: cover;
    background-position: center center;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    animation: fadeIn 1s ease-out;
    position: relative;
  }
  
  @keyframes fadeIn {
    from {
      opacity: 0;
      transform: translateY(30px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
  
  .page-title {
    text-align: center;
    font-size: 32px; 
    margin-bottom: 30px;
    font-weight: 700;
    letter-spacing: 1px;
  }
  
  .form-container {
    display: flex;
    flex-direction: column;
    background-color: rgba(255, 255, 255, 0.7); 
    border-radius: 12px;
    padding: 30px;
    position: relative;
    z-index: 2; 
  }
  
  .el-form-item {
    margin-bottom: 25px;
  }
  
  .input-field {
    border-radius: 10px;
    padding: 14px 18px;
    font-size: 15px;
    background-color: #ffffff;
    border: 1px solid #ddd;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
  }
  
  .input-field:focus {
    border-color: #4a90e2;
    box-shadow: 0 0 8px rgba(74, 144, 226, 0.5);
  }
  
  .save-btn {
    padding: 14px 28px;
    font-size: 18px;
    border-radius: 30px;
    background: linear-gradient(135deg, #4a90e2, #50e3c2);
    color: white;
    width: 100%;
    border: none;
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.3s ease;
  }
  
  .save-btn:hover {
    background: linear-gradient(135deg, #50e3c2, #4a90e2);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.15);
  }
  
  .save-btn:active {
    transform: scale(0.98);
  }
  
  .el-form-item label {
    font-size: 16px;
    color: #333;
    font-weight: 600;
  }
  </style>